package com.yyj.controller;

import com.yyj.entity.Count;
import com.yyj.entity.Result;
import com.yyj.service.CountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/count")
public class CountController {
    @Autowired
    private CountService countService;

    @GetMapping("/allCount")
    public Result getCount() {
        List<Map<String, Object>> mapList = new ArrayList<>();
        Integer waitCount = countService.getWaiteCount();
        Integer outCount = countService.getOutCount();
        Count obj1 = new Count("已领养的总数", outCount);
        Count obj2 = new Count("待领养的总数", waitCount);
        Map<String, Object> myMap1 = new HashMap<>();
        myMap1.put("name", obj1.getName());
        myMap1.put("value", obj1.getValue());
        Map<String, Object> myMap2 = new HashMap<>();
        myMap2.put("name", obj2.getName());
        myMap2.put("value", obj2.getValue());
        mapList.add(myMap1);
        mapList.add(myMap2);
        // 现在，你的 Map 包含了这些键值对
        return Result.success(mapList);
    }

    @GetMapping("/allApplicationCount")
    public Result getApplicationCount() {
        List<Map<String, Object>> mapList = new ArrayList<>();
        Integer reviewCount = countService.getReviewCount();
        Integer completeCount = countService.getCompleteCount();
        Count obj1 = new Count("待审核申请", reviewCount);
        Count obj2 = new Count("已审核申请", completeCount);
        Map<String, Object> myMap1 = new HashMap<>();
        myMap1.put("name", obj1.getName());
        myMap1.put("value", obj1.getValue());
        Map<String, Object> myMap2 = new HashMap<>();
        myMap2.put("name", obj2.getName());
        myMap2.put("value", obj2.getValue());
        mapList.add(myMap1);
        mapList.add(myMap2);
        // 现在，你的 Map 包含了这些键值对
        return Result.success(mapList);
    }
}
